package xju.msg.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import xju.msg.entity.Msg;
import xju.msg.entity.MsgVo;

public interface MsgMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(Msg record);

    Msg selectByPrimaryKey(Integer id);

    List<Msg> selectAll();

    int updateByPrimaryKey(Msg record);

    @Select("SELECT * FROM msg  WHERE reply_id is null ORDER BY create_time DESC")
    @Results({
            @Result(property = "id",column = "id",id = true),
            @Result(property = "nickname",column = "nickname"),
            @Result(property = "qq",column = "qq"),
            @Result(property = "email",column = "email"),
            @Result(property = "text",column = "text"),
            @Result(property = "replyId",column = "reply_id"),
            @Result(property = "createTime",column = "create_time"),
            @Result(property = "replyList",
                    column = "id",
            javaType = List.class,
            many = @Many(select = "xju.msg.mapper.MsgMapper.selectByReplyId"))
    })
    List<MsgVo> pageList();

    @Select("SELECT * FROM msg WHERE reply_id = #{replyId}")
    List<Msg> selectByReplyId(Integer replyId);
}